﻿using System.Data; 

namespace Microsoft.Extensions.DependencyInjection;
 
public  class DbConnectionFactory
{
    private IServiceProvider _serviceProvider { get; set; }
    private Dictionary<string, Type> _connections;

    public DbConnectionFactory(IServiceProvider provider, Dictionary<string, Type> connections)
    {
         _serviceProvider = provider;
         _connections = connections; 
    }
    public IDbConnection? Create(string name)
    { 
        if (_connections.TryGetValue(name,out Type? connectionYype))
        {
            return ActivatorUtilities.CreateInstance(_serviceProvider, connectionYype) as IDbConnection;
        }
        return default;
    }
}
public interface IDbConnection
{

}
public class SqlDbConnection: IDbConnection
{

}

public class MySqlDbConnection : IDbConnection
{

}